/**
 * 设置信息
 * @param {object} key 
 *  @param {object} value
 *  @param {object} iDay
 */

import { GetDomain } from "@/api/api";
import BASE from "./base";
async function GetDomainFn(){
    let res = await GetDomain({});
    console.log(res);
    return res.data.data;
}
export const setCookie = async (key, value, iDay) => {
    var oDate = new Date();
    oDate.setDate(oDate.getDate() + iDay);
    let DomainStr = await GetDomainFn();
    // let DomainStr = '';
    // if (BASE.IP == 'http://192.168.33.89:8085') {
    //     DomainStr = '';
    // }
    // if (BASE.IP == 'http://192.168.33.89:8095') {
    //     DomainStr = '';
    // }
    // if (BASE.IP == 'https://eng-dev-api.a-mis.com') {
    //     DomainStr = '.a-mis.com';
    // }
    // if (BASE.IP == 'https://demoapi.richtechcn.com') {
    //     DomainStr = '.richtechcn.com';
    // }
    let cookie = document.cookie = key + '=' + value + ';expires=' + oDate + ';Domain=' + DomainStr;
    return cookie
}

/**
 * 获取信息
 * @returns {string}
 */
export const getCookie = (key) => {
    var cookieArr = document.cookie.split('; ');
    for (var i = 0; i < cookieArr.length; i++) {
        var arr = cookieArr[i].split('=');
        if (arr[0] === key) {
            return arr[1];
        }
    }
    return "";
}

export const removeCookie = (key) => {
    return setCookie(key, '', -1)
}